<template>
  <div class="comm-list">
    <div class="bookd-comment">
      <div class="bookdco-title-cont">
        <span class="bookdco-title">作品评论区&nbsp;</span>
        <span class="bookdco-count">({{comment.total}}条)</span>
        <span class="bookdco-new" @click="$refs['bookde-cont'].focus();">发表评论</span>
      </div>
      <div class="bookdco-user" v-for="item in comment.list" :key="item.id">
        <div class="bookdcou-pic">
          <img :src="item.createUserPhoto?item.createUserPhoto:require('../../../assets/images/man.png')" alt="" class="bookdcou-pic-img">
        </div>
        <div class="bookdcou-say">
          <p class="bookdcou-mobile">{{item.createUserName}}</p>
          <div class="bookdcou-cont">{{item.commentContent}}</div>
          <p class="boodcou-time">{{item.createTime}}</p>
        </div>
      </div>
      <div class="bookdco-noany" v-if="comment.list.length == 0">
        <img src="../../../assets/images/no_comment.png" alt="" class="bookdco-noimg">
        <p class="bookdco-nomsg">暂无评论</p>
      </div>
    </div>
    <el-pagination class="all-book-pagination" v-if="showType == 'all'"
      background
      layout='prev, pager, next, jumper'
      :total="comment.total"
      @current-change="handlerPageChange">
    </el-pagination>
    <router-link :to="'/index/bookCommentlist?bookId='+bookId" v-if="showType == 'detail'">
      <div class="bookd-comment-all" v-if="comment.list.length > 0">查看全部评论></div>
    </router-link>
    <div class="bookd-evalu">
      <p class="bookde-title">发表评论</p>
      <textarea ref="bookde-cont" v-model="commentCont" name="" id="" class="bookde-cont" placeholder="我来说两句..."></textarea>
      <div class="bookde-confirm">
        <span class="bookde-count">{{commentCont.length}}/512字</span>
        <span class="bookde-conf-btn" @click="addBookComment()">发表</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props:{
    bookId:String,
    showType:{
      type:String,
      default:'detail'
    }
  },
  data(){
    return {
      pageParam:{
        curr:1,
        limit:this.showType=='detail'?3:10,
        bookId:this.bookId
      },
      comment:{
        total:0,
        list:[]
      },
      commentCont:''
    }
  },
  created(){
    this.listCommentByPage();
  },
  methods:{
    listCommentByPage(){
      this.$http.postForm('/book/listCommentByPage', this.pageParam, res=>{
        this.comment.total = parseInt(res.total);
        this.comment.list = res.list;
      })
    },
    addBookComment(){
      if(this.util.checkTextForbid(this.commentCont)){
        return;
      }
      this.$http.postForm('/book/addBookComment', {bookId:this.bookId,commentContent:this.commentCont}, res=>{
        this.commentCont = '';
        this.pageParam.curr = 1;
        this.listCommentByPage();
      });
    },
    handlerPageChange(currentPage){
      this.pageParam.curr = currentPage;
      this.listCommentByPage();
    }
  }
}
</script>

<style lang='scss' scoped>
.bookd-comment {
  .bookdco-title-cont {
    border: 1px solid #eee;
    border-width: 0 0 1px 0;
    line-height: 30px;
    margin-bottom: 15px;
    .bookdco-title {
      font-size: 20px;
      font-weight: bold;
    }
    .bookdco-count {
      color: #666;
    }
    .bookdco-new {
      cursor: pointer;
      position: relative;
      right: 0;
      color: #333;
      float: right;
      margin-right: 15px;
      color: #333;
    }
    .bookdco-new:hover{
      color: $base-color;
    }
  }

  .bookdco-user {
    .bookdcou-pic {
      width: 70px;
      display: inline-block;
      vertical-align: top;
      padding-top: 10px;
      .bookdcou-pic-img {
        width: 50px;
        height: 50px;
      }
    }

    .bookdcou-say {
      display: inline-block;
      width: calc(100% - 80px);
      .bookdcou-mobile {
        color: #666;
      }
      .bookdcou-cont {
        word-wrap: break-word;
        font-size: 13px;
      }
      .boodcou-time {
        color: #999;
        font-size: 13px;
      }
    }
  }
  .bookdco-noany{
    // height: 300px;
    text-align: center;
    .bookdco-noimg{
      // margin: 70px auto 0 auto;
      width: 100px;
      height: 100px;
    }
    .bookdco-nomsg{
      margin-top: 0;
      color: #CCC;
    }
  }
}
.all-book-pagination{
  margin: 10px 0 20px 0;
}
.bookd-comment-all {
  margin: 10px 0 20px 0;
  width: 100%;
  height: 30px;
  background-color: #f7f7f7;
  text-align: center;
  line-height: 30px;
  font-size: 12px;
  color: #666;
}

.bookd-evalu {
  .bookde-title {
    font-size: 18px;
  }
  .bookde-cont {
    margin: 5px 0 10px 0;
    width: 100%;
    height: 110px;
    border: 1px solid #eaeaea;
    border-radius: 5px;
    padding: 10px;
    box-shadow: 0 0 4px 2px hsla(0,0%,92%,.35);
    outline: none;
    resize: none;
    box-sizing: border-box;
  }

  .bookde-confirm {
    height: 35px;
    .bookde-count {
      color: #999;
    }
    .bookde-conf-btn {
      cursor: pointer;
      width: 90px;
      color: #fff;
      height: 35px;
      line-height: 35px;
      text-align: center;
      border-radius: 20px;
      background-color: $base-color;
      float: right;
    }
  }
}
</style>